/**
 * Define functions which be used as common function
 * @author: snipe@crebird.com
 */
CrebirdFuncion = function(options) {
  this.init(options);
}

$.extend(CrebirdFuncion.prototype, {
  options: '',
  init: function(options) {
    if (options)
      this.options = options;
  },
  /**
   * Define again ajax method
   * @author: snipe@crebird.com
   */
  callAjax: function(type, url, data, successFn, failFn) {
    if (!type) {
      type = 'POST';
    }

    if (!data) {
      data = {};
    }

    if (!successFn) {
      successFn = function() {
      };
    }

    if (!failFn) {
      failFn = function() {
        alert('Máy chủ đang không hoạt động!')
      };
    }

    var timeout = function() {
      alert('timeout!');
    }

    jQuery.ajax({
      type: type,
      url: url,
      data: data,
      success: function(res, status) {
        successFn(res, status)
      },
      error: failFn,
      timeout: timeout
    });
  },
  /**
   * Overite ajax post method
   * @author: snipe@crebird.com
   */
  post: function(url, data, successFn, failFn) {
    this.callAjax('POST', url, data, successFn, failFn)
  },
  /**
   * Overite ajax get method
   * @author: snipe@crebird.com
   */
  get: function(url, data, successFn, failFn) {
    this.callAjax('GET', url, data, successFn, failFn)
  },
  searchForm: function() {
    if ($('#search_icon').hasClass('icon-plus-alt')) {
      $('#search_form').show();
      $('#search_icon').removeClass('icon-plus-alt');
      $('#search_icon').addClass('icon-minus-alt');
    } else {
      $('#search_form').hide();
      $('#search_icon').removeClass('icon-minus-alt');
      $('#search_icon').addClass('icon-plus-alt');
    }
  },
  scrollToAnchor: function (objName){
    var obj = $(objName);
    $('html,body').animate({scrollTop: obj.offset().top }, 'slow');
  },
});

var commonFn = new CrebirdFuncion();